package edu.zut.cs.software.perfect.process.web.spring.controller;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;

import edu.zut.cs.software.perfect.base.web.spring.controller.GenericController;
import edu.zut.cs.software.perfect.process.domain.CourseProcess;
import edu.zut.cs.software.perfect.process.domain.ProcessRegistrar;
import edu.zut.cs.software.perfect.process.service.CourseProcessManager;
import edu.zut.cs.software.perfect.process.service.ProcessRegistrarManager;

/**
 * @ClassName ProcessRegistrarController
 * @Description TODO
 * @Author niu-xi
 * @Date 2020年5月30日 上午12:23:52
 * @Version 1.0
 */
@ResponseBody
@Controller
@RequestMapping("/processRegistrar")
public class ProcessRegistrarController extends GenericController<ProcessRegistrar,Long,ProcessRegistrarManager>{
	
	ProcessRegistrarManager processRegistrarManager;

	@Autowired
	public void setProcessRegistrarManager(ProcessRegistrarManager processRegistrarManager) {
		this.processRegistrarManager = processRegistrarManager;
		this.manager=this.processRegistrarManager;
	}
	
	@ResponseBody
    @GetMapping(value = "findall", produces = "application/json;charset=utf-8")
	public String findAllProcessRegistrar() {
		List<ProcessRegistrar> processRegistrarList = this.manager.findAll();
        @SuppressWarnings({ "rawtypes", "unchecked" })
		PageInfo pageInfo = new PageInfo(processRegistrarList);
        return JSON.toJSONString(pageInfo);
	}
	
	@GetMapping("/findbyid/{id}")
	public String findById(@PathVariable("id") Long id) {
		Optional<ProcessRegistrar> result = this.manager.findByCourseId(id);
		return JSON.toJSONString(result);
	}
	
	

	@GetMapping("/deletebyid/{id}")
	public Boolean deleteById(@PathVariable("id") Long id) {
		Boolean result = this.manager.deleteById(id);
		return result;
	}
	
	

}
